# -*- coding: utf-8 -*-

from wxapp.models import ServiceDetail
from wxapp.models import GoodsDetail
from wxapp.models import ShoppingCartDetail


#-------------project bag---------------
from wxapp.base.log import logger
import shoppingcar_mgr

all_goodsID = set()


'''
需要给前端的数据前面加多c_标识，不能将重要的数据外泄出去
'''


class GoodsObj:
	global all_goodsID
	all_goodsID_list = all_goodsID
	def __init__(self, id):
		self.id = int(id)
		self.goodsObj = GoodsDetail.objects.get(goods_id=self.id)
		self.name = self.get_goodsName()
		if not self.id in GoodsObj.all_goodsID_list:
			logger.info('error:cannot found goods ID %s' % (str(self.id)))

	def get_goodsID(self):
		return int(self.id)
		
	def get_goodsName(self):
		name = self.goodsObj.goods_name
		return str(name)

	def get_goodsPrice(self):
		return float(self.goodsObj.goods_price)

	def get_goodsCost(self):
		return float(self.goodsObj.goods_cost)

	def get_goodsNum(self):
		return float(self.goodsObj.goods_num)

	def get_sellNum(self):
		return float(self.goodsObj.sell_num)

	def get_goodsType(self):
		return str(self.goodsObj.goods_type)

	def get_belongCar(self):
		return str(self.goodsObj.belong_car)

	def get_pulishTime(self):
		return str(self.goodsObj.publish_time)

	def get_goodsDiscount(self):
		return float(self.goodsObj.goods_discount)

	def get_goodStatus(self):
		return int(self.goodsObj.goods_status)

	def get_picPath(self):
		return str(self.goodsObj.pic_path)

	def del_goods(self):
		if not self.get_goodStatus() == 1:
			self.goodsObj.goods_status = 1
			self.goodsObj.save()
		else:
			return None

	# def c_get_my_shoppingCart(self):
	# 	all_cartID = shoppingcar_mgr.all_cartID
	# 	for id in all_cartID:
	# 		if shoppingcar_mgr(id).get_userID() == self.id:
	# 			pass



def get_all_goodsID():
	global all_goodsID
	all_goods = GoodsDetail.objects.all().values('goods_id')
	for goods in all_goods:
		all_goodsID.add(int(goods['goods_id']))
	return all_goodsID


def c_get_all_goodsDetail():
	all_goods_list = []
	all_goods = GoodsDetail.objects.values()
	for goods in all_goods:
		goods_detail = {}
		goods_detail['goods_id'] = goods['goods_id']
		goods_detail['goods_name'] = goods['goods_name']
		goods_detail['goods_price'] = goods['goods_price']
		goods_detail['goods_type'] = goods['goods_type']
		goods_detail['belong_car'] = goods['belong_car'] 
		goods_detail['goods_status'] = goods['goods_status']
		goods_detail['pic_path'] = goods['pic_path']
		all_goods_list.append(goods_detail)
	return all_goods_list
